package com.hu.gulimallproduct.project.controller;

import com.hu.gulimallcommon.utils.PageUtils;
import com.hu.gulimallcommon.utils.R;
import com.hu.gulimallproduct.project.entity.PmsProductAttrValueEntity;
import com.hu.gulimallproduct.project.service.PmsAttrService;
import com.hu.gulimallproduct.project.service.PmsProductAttrValueService;
import com.hu.gulimallproduct.project.vo.PmsAttrRespVO;
import com.hu.gulimallproduct.project.vo.PmsAttrVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 商品属性
 *
 * @author hbt
 * @email 2188748205@qq.com
 * @date 2024-05-20 12:32:11
 */
@RestController
@RequestMapping("product/attr")
public class PmsAttrController {
    @Autowired
    private PmsAttrService pmsAttrService;

    @Autowired
    private PmsProductAttrValueService productAttrValueService;
    /**
     * 产品属性
     */
    @GetMapping("/updata/{spuId}")
    public R updateSpuAttr(@PathVariable("spuId") Long spuId,
                           @RequestBody List<PmsProductAttrValueEntity> entities){
        productAttrValueService.updateSpuAttr(spuId,entities);
        return R.ok();
    }
    /**
     * 产品属性
     */
    @GetMapping("/base/listforspu/{spuId}")
    public R baseAttrlistforspu(@PathVariable("spuId") Long spuId){
        List<PmsProductAttrValueEntity> catelogPath = productAttrValueService.baseAttrlistforspu(spuId);
        return R.ok().put("data",catelogPath);
    }
    /**
     * 列表
     */
    @RequestMapping("/{attrType}/list/{catelogId}")
    public R baseList(@PathVariable Long catelogId ,@PathVariable String attrType,@RequestParam Map<String, Object> params){
        PageUtils page = pmsAttrService.baseList(catelogId,attrType,params);

        return R.ok().put("page", page);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = pmsAttrService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    public R info(@PathVariable("attrId") Long attrId){
//		PmsAttrEntity pmsAttr = pmsAttrService.getById(attrId);
        PmsAttrRespVO respVO = pmsAttrService.getInfo(attrId);
        return R.ok().put("attr", respVO);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody PmsAttrVO pmsAttr){
		pmsAttrService.saveDetail(pmsAttr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody PmsAttrVO pmsAttr){
		pmsAttrService.updateDetail(pmsAttr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] attrIds){
		pmsAttrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
